package com.sy.learn;

/**
 * 可变参数
 */
public class java_0223 {
    public static void main(String[] args) {
        HspMethod m = new HspMethod();
        //整形数组
        int res = m.sum(1, 2, 3, 4, 5);
        System.out.println(res);

        //字符串数组
        String b = m.sum("a", "b", "c");
        System.out.println(b);
    }
}

class HspMethod {
    public int sum(int... nums) {
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            res += i;
        }
        return res;
    }

    public String sum(String... arr) {
        String a = "";
        for (int i = 0; i < arr.length; i++) {
            a += arr[i];
        }
        return a;
    }
}
